package com.elinkway.infinitemovies.bean;

import android.content.Context;
import android.text.SpannableString;
import android.text.TextUtils;
import android.text.style.AbsoluteSizeSpan;

import com.elinkway.infinitemovies.application.MoviesApplication;
import com.elinkway.infinitemovies.utils.MoviesConstant;
import com.le123.ysdq.R;

/**
 * 海报图bean共用基类<br>
 * 用于获取生成对应分类视频的短描述字串
 * <p>
 * 现有规则：<br>
 * 		电影：显示%1.f格式评分 <br>
 *     电视剧：显示“更新到%d集”(未完结)，或“全%d集”(已完结)<br>
 *     动漫：同电视剧<br>
 *     综艺：显示最新一期的期数，如20140707<br>
 *     其他：同电影<br>
 *     </p>
 * @author liuliwei
 *
 */
public abstract class GridPosterBase {

	/**
	 * 组装返回用于显示的专辑信息
	 * <p>
	 * 若需要返回自定义字体大小的SpannableString请使用{@link GridPosterBase#getEpisodeInfoInSpannableString(Context, int, int)}
	 * </p>
	 * @return
	 * 返回格式为String
	 */
	public String getEpisodeInfoInString() {
		if (null != this) {
			String vt = this.getVt();
			String isSend = this.getIsend();
			if (MoviesConstant.VT_CARTOON.equals(vt)
					|| MoviesConstant.VT_TV.equals(vt)) {
				if (!TextUtils.isEmpty(this.getIsend())
						&& !TextUtils.isEmpty(this.getNowepisodes())) {
					StringBuffer nameBuff = new StringBuffer();
					// 如果正在更新剧集
					if (MoviesConstant.EPISODE_UPDATE.equals(isSend)) {
						nameBuff.append(MoviesApplication.getInstance().getString(R.string.updateto));
						nameBuff.append(this.getNowepisodes());
						nameBuff.append(MoviesApplication.getInstance().getString(R.string.episode));
					} else if (MoviesConstant.EPISODE_UPDATE_END.equals(isSend)) {
						// 如果是全集
						nameBuff.append(this.getEpisodes());
						nameBuff.append(MoviesApplication.getInstance().getString(R.string.episode_total));
					}
					if(!TextUtils.isEmpty(this.getNowepisodes())){
						return nameBuff.toString();
					}else{
						return "";
					}
				}
			} else if (MoviesConstant.VT_ZONGYI.equals(vt) || MoviesConstant.VT_DOCUMENTARY.equals(vt) ) {
				if(!TextUtils.isEmpty(this.getNowepisodes())){
					if(MoviesConstant.EPISODE_UPDATE_END.equals(isSend)){
						if(TextUtils.isEmpty(this.getEpisodes())){
							return "";
						}
						return "共"+ this.getEpisodes()+ "期";
					}else{
						return "更新至"+ this.getNowepisodes()+ "期";
					}
				}else{
					return "";
				}
			} else {
				if(!TextUtils.isEmpty(this.getRating())){
					return this.getRating()+ "分";
				}else{
					return "";
				}
			}
		}
		return null;
	}
	
	/**
	 * 组装返回格式为SpannableString的用于显示的专辑信息<br>
	 * 若为评分信息，则设定为评分信息的字体大小<br>
	 * 若为其他信息，则设定为其他信息的字体大小<br>
	 * <p>
	 * 若需要返回纯文字请使用{@link GridPosterBase#getEpisodeInfoInString(Context)}
	 * </p>
	 * @param context
	 * @param scoreSize 评分信息字体大小 单位为sp
	 * @param otherSize 其他信息字体大小 单位为sp
	 * @return 返回携带字体大小的SpannableString
	 */
	public SpannableString getEpisodeInfoInSpannableString(Context context,int scoreSize,int otherSize) {
		SpannableString ss;
		if (null != this && !TextUtils.isEmpty(this.getVt())) {
			String vt = this.getVt();
			// 如果当前的影片类型为电影
			if (MoviesConstant.VT_MOVIE.equals(vt)) {
				ss = new SpannableString(this.getRating() + "分");
				ss.setSpan(new AbsoluteSizeSpan(scoreSize,true), 0, ss.length(), 0);
				return ss;
			} else if (MoviesConstant.VT_CARTOON.equals(vt)
					|| MoviesConstant.VT_TV.equals(vt)) {
				if (!TextUtils.isEmpty(this.getIsend())
						&& !TextUtils.isEmpty(this.getNowepisodes())) {
					StringBuffer nameBuff = new StringBuffer();
					String isSend = this.getIsend();
					// 如果正在更新剧集
					if (MoviesConstant.EPISODE_UPDATE.equals(isSend)) {
						nameBuff.append(context.getString(R.string.updateto));
						nameBuff.append(this.getNowepisodes());
						nameBuff.append(context.getString(R.string.episode));
					} else if (MoviesConstant.EPISODE_UPDATE_END.equals(isSend)) {
						// 如果是全集
						nameBuff.append(this.getNowepisodes());
						nameBuff.append(context
								.getString(R.string.episode_total));
					}
					ss = new SpannableString(nameBuff.toString());
					ss.setSpan(new AbsoluteSizeSpan(otherSize,true), 0, ss.length(), 0);
					return ss;
				}
			} else if (MoviesConstant.VT_ZONGYI.equals(vt)) {
				ss = new SpannableString(this.getNowepisodes());
				ss.setSpan(new AbsoluteSizeSpan(otherSize,true), 0, ss.length(), 0);
				return ss;
			} else {
				ss = new SpannableString(this.getRating());
				ss.setSpan(new AbsoluteSizeSpan(13,true), 0, ss.length(), 0);
				return ss;
			}
		}
		return null;
	}
	/**
	 * 组装返回格式为SpannableString的用于显示的专辑信息<br>
	 * 若为评分信息，默认13sp<br>
	 * 若为其他信息，默认10sp<br>
	 * <p>
	 * 若需要返回纯文字请使用{@link GridPosterBase#getEpisodeInfoInString(Context)}
	 * </p>
	 * @param context
	 * @return 携带字体大小属性的SpannableString
	 */
	public SpannableString getEpisodeInfoInSpannableString(Context context){
		return getEpisodeInfoInSpannableString(context, 10, 10);
	}
	public abstract String getVt();
	public abstract String getIsend();
	public abstract String getNowepisodes();
	public abstract String getRating();
	public abstract String getEpisodes();
}
